package com.dhcc.wb.interfaces;

import com.dhcc.bussiness.page.PageBean;
import com.dhcc.wb.operationlog.OperationLogModel;
import com.dhcc.wb.operationlog.OperationLogService;
import com.opensymphony.xwork2.ActionSupport;
import org.apache.log4j.Logger;
import org.apache.struts2.ServletActionContext;
import org.codehaus.jackson.map.ObjectMapper;
import utils.JsonUtils;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 操作日志接口
 * @author wanggx
 * @date 2019/12/3 16:55
 */
public class OperationLogAction extends ActionSupport {
    private static Logger logger = Logger.getLogger(OperationLogAction.class);
    private PageBean<OperationLogModel> pageBean = new PageBean<OperationLogModel>();
    private Integer currentCount = 10;
    OperationLogService service = new OperationLogService();
    private HttpServletResponse response;
    public void operationLogAction() throws IOException {
        response = ServletActionContext.getResponse();
        response.setHeader("Content-Type", "application/json;charset=UTF-8");
        ObjectMapper objectMapper = new ObjectMapper();
        HttpServletRequest request = ServletActionContext.getRequest();
        int currentPage = Integer.parseInt(request.getParameter("currentPage")==null?"1":request.getParameter("currentPage"));//规定是第一页
        String name = request.getParameter("name");
        String typeName = request.getParameter("typeName");
        logger.info("===传入的用户==="+name+ "===传入的内容===="+typeName);
        if (typeName.equals("点击选择操作内容")){
            typeName = "";
        }
        pageBean = service.findSh_logServiceByPage(currentPage,currentCount,name,typeName);
        objectMapper.writeValue(response.getWriter(), JsonUtils.getJSON(pageBean, "success", "获取数据成功,直接跳转页面"));

    }

}
